package iscas;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.Pipeline;

public class LocalMapStateRemoteMerger<K, V> extends LocalMapState<K, V> {
    final String script;

    public LocalMapStateRemoteMerger(String name, long period, String script) {
        super(name, null, null, null, period);
        this.script = script;
    }

    @Override
    public void merge(Jedis jedis) {
        Pipeline pipeline = jedis.pipelined();
        local.keySet().forEach(k -> pipeline.evalsha(script, 3, name, k.toString(), local.remove(k).toString()));
        pipeline.sync();
    }
}
